package com.yy.yyui.button
{
	import com.siku.manor.view.component.GT;
	import com.siku.manor.view.component.IDataContainer;
	import com.siku.manor.view.component.IDrop;
	import com.siku.manor.view.component.ISelectable;
	
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class RadioButton extends SimpleButton implements ISelectable,IDataContainer,IDrop
	{
		private var _selectedState:DisplayObject;
		private var _disableState:DisplayObject;
		
		private var _bakUpState:DisplayObject;
		private var _bakOverState:DisplayObject;
		
		private var _selected:Boolean;
		
		private var _actions:Object;
		
		private var _data:Object;		
		public function RadioButton(selectedState:DisplayObject=null,disableState:DisplayObject=null,upState:DisplayObject=null, overState:DisplayObject=null, downState:DisplayObject=null, hitTestState:DisplayObject=null)
		{
			//TODO: implement function
			super(upState, overState, downState, hitTestState);
			this._selectedState = selectedState;
			this._disableState = disableState;
			this._bakUpState = upState;
			this._bakOverState = overState;

			this._selected = false;
			
			//set actions
			this.addEventListener(MouseEvent.CLICK,clickHandler);
			this._actions = {};
			this.onDrop = null;
			this.onDropCheck = null;
			
			this.addEventListener(Event.REMOVED_FROM_STAGE,destroy);
		}
		
		public function destroy(...rest):void{
			this.removeEventListener(Event.REMOVED_FROM_STAGE,destroy);
			GT.destroyActions(this.actions);		
		}
		
		public function get data():Object{
			return _data;
		}
		
		public function set data(value:Object):void{
			this._data = value;
		}
		
		private function clickHandler(e:Event):void{
			this.onSelect(e);
		}
		
		public function get disableState():DisplayObject{
			return this._disableState;
		}
		
		public function set disableState(value:DisplayObject):void{
			this._disableState = value;
		}
		
		public function get selectedState():DisplayObject{
			return this._selectedState;
		}
		
		public function set selectedState(value:DisplayObject):void{
			this._selectedState = value;
		}
		
		public function get actions():Object
		{
			//TODO: implement function
			return this._actions;
		}
		
		public function get selected():Boolean
		{
			//TODO: implement function
			return this._selected;
		}
		
		public function set selected(value:Boolean):void
		{
			//TODO: implement function
			if(!this.enabled){
				return;
			}
			this.upState = value?this.selectedState:this._bakUpState;
			this.overState = value?this.selectedState:this._bakOverState;
			this._selected = value;
		}
		
		override public function set enabled(value:Boolean):void{
			this.upState = value?this._bakUpState:this.disableState;
			super.enabled = value;
			this.mouseEnabled = value;
			if(!value){
				this.selected = false;
			}
		}

		public function get onSelect():Function
		{
			//TODO: implement function
			return this.actions.onSelect;
		}
		
		public function set onSelect(value:Function):void
		{
			//TODO: implement function
			this.actions.onSelect = value;
		}
		
		public function set onDrop(value:Function):void{
			this.actions.onDrop = value;
		}
		
		public function get onDrop():Function{
			return this.actions.onDrop;
		}			
		
			
		public function set onDropCheck(value:Function):void{this.actions.onDropCheck = value;}
		public function get onDropCheck():Function{return this.actions.onDropCheck;}		
	}
}